
function ListItem({data,changeAmount}) {
    const { id,title,price,amount,totalPrice } = data;
    return (
        <li>
            <button onClick={ ()=>{
                const newamout = amount-1 >= 0 ? amount-1:0;
                const newtotalPrice = price*newamout;  
                changeAmount(id,newamout,newtotalPrice)
            }} >-</button><span>{amount}</span>
            <button onClick ={ () =>{
                const newamout = amount+1;
                const newtotalPrice = price*newamout;  
                changeAmount(id,newamout,newtotalPrice)
            } }>+</button>
            {title}
            单价为 ${price}
            总价格:${totalPrice}
        </li>
    )
}

export default ListItem

